package simpleGeom;

import java.util.ArrayList;
import java.util.List;

public class MeshFace extends Face3D {

	public ArrayList<MeshEdge> getEdges() {
		ArrayList<MeshEdge> edges = new ArrayList<MeshEdge>();
		for (int i = 0; i < this.getNNodes(); i++) {
			MeshNode node1 = (MeshNode) getNode(i);
			MeshNode node2 = (MeshNode) getNode(i + 1);
			MeshEdge edge = node1.getEdge(node2);
			if (edge != null)
				edges.add(edge);
		}
		return edges;
	}

	public MeshFace() {
	}

	public MeshFace(HasPos3D n1, HasPos3D n2, HasPos3D n3, HasPos3D n4) {
		super(n1, n2, n3, n4);
		// TODO Auto-generated constructor stub
	}

	public MeshFace(HasPos3D n1, HasPos3D n2, HasPos3D n3) {
		super(n1, n2, n3);
		// TODO Auto-generated constructor stub
	}

	public MeshFace(HasPos3D[] nodes) {
		super(nodes);
		// TODO Auto-generated constructor stub
	}

	public MeshFace(List<? extends HasPos3D> nodes) {
		super(nodes);
		// TODO Auto-generated constructor stub
	}

	public MeshFace getCopy() {
		MeshFace face = new MeshFace();
		face.setData(this.getData());
		face.comment = comment;
		face.setNodes(this.getNodes());
		return face;
	}

	public ArrayList<MeshFace> getNbFaces() {
		ArrayList<MeshEdge> edges = this.getEdges();
		ArrayList<MeshFace> faces = new ArrayList<MeshFace>();
		for (int i = 0; i < edges.size(); i++) {
			MeshEdge edge = edges.get(i);
			MeshFace nbFace = edge.getOtherFace(this);
			if (nbFace != null) {
				faces.add(nbFace);
			}
		}
		// TODO Auto-generated method stub
		return faces;
	}

	public float getCurvature() {
		ArrayList<MeshFace> faces = this.getNbFaces();
		Vec3D center = this.getGravityCenter();
		Vec3D normal = this.getNormal();
		Vec3D normalcenter = Vec3D.add(center, normal);
		float sumD = 0;
		for (int i = 0; i < faces.size(); i++) {
			MeshFace nb = faces.get(i);
			Vec3D cCenter = nb.getGravityCenter();
			Vec3D cNormal = nb.getNormal();
			Vec3D cNormalcenter = Vec3D.add(cCenter, cNormal);
			float cD = center.dist(cCenter);
			float cN = normalcenter.dist(cNormalcenter);
			sumD += (cD - cN);
		}
		return sumD / faces.size();
	}

	@Override
	public MeshNode getNode(int i) {
		// TODO Auto-generated method stub
		return (MeshNode) super.getNode(i);
	}

}
